Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
case-anything
Advanced tools
camelCase, kebab-case, PascalCase... a simple integration with nano package size. (SMALL footprint!)
npm i case-anything
10 case changing functions: camelCase, kebab-case, PascalCase and more...
A simple integration with nano package size. (SMALL footprint!)
I created this package because most other packages that do simple case changing are so big...
I wanted to try my hand at the smallest iteration possible. (and it's 12+ times smaller than the next popular case changing package!!)
There's also a Better Touch Tool preset with keyboard shortcuts to convert selected text system wide!
case-anything supports tree-shaking and is side-effect free!
import { camelCase, pascalCase, kebabCase, snakeCase, constantCase } from 'case-anything'
const str = 'PonytaVaporeon_poliwrath-BUTTERFREE'
// or any variant on this
camelCase(str) === 'ponytaVaporeonPoliwrathButterfree'
pascalCase(str) === 'PonytaVaporeonPoliwrathButterfree'
kebabCase(str) === 'ponyta-vaporeon-poliwrath-butterfree'
snakeCase(str) === 'ponyta_vaporeon_poliwrath_butterfree'
constantCase(str) === 'PONYTA_VAPOREON_POLIWRATH_BUTTERFREE'
There is also spaceCase
and pathCase
, which does not convert the casing:
import { spaceCase, pathCase } from 'case-anything'
const str = 'PonytaVaporeon_poliwrath-BUTTERFREE'
spaceCase(str) === 'Ponyta Vaporeon poliwrath BUTTERFREE'
pathCase(str) === 'Ponyta/Vaporeon/poliwrath/BUTTERFREE'
There is also upper, lower and capital case. These will all convert the casing & also add spaces in between:
import { upperCase, lowerCase, capitalCase } from 'case-anything'
const str = 'PonytaVaporeon_poliwrath-BUTTERFREE'
upperCase(str) === 'PONYTA VAPOREON POLIWRATH BUTTERFREE'
lowerCase(str) === 'ponyta vaporeon poliwrath butterfree'
capitalCase(str) === 'Ponyta Vaporeon Poliwrath Butterfree'
As soon as there is a space in the target string, it will regard the input as a sentence and only split each part at the spaces.
See this example to understand each case:
const str = `listen I'm O.K.!`
// splits on spaces & removes special characters
camelCase(str) === 'listenImOk'
pascalCase(str) === 'ListenImOk'
kebabCase(str) === 'listen-im-ok'
snakeCase(str) === 'listen_im_ok'
constantCase(str) === 'LISTEN_IM_OK'
// splits on spaces & keeps special characters
spaceCase(str) === `listen I'm O.K.!`
pathCase(str) === `listen/I'm/O.K.!`
lowerCase(str) === `listen i'm o.k.!`
upperCase(str) === `LISTEN I'M O.K.!`
capitalCase(str) === `Listen I'm O.k.!`
Also note, that multiple sequential spaces are treated as one space.
I have extended regular alphabet with the most common Latin-1 Supplement special characters.
The coolest thing about this library is that it will "convert" special characters into regular alphabet for the cases used as variable names! 😎
const str = 'Çâfé Ågård'
// CONVERTS special characters:
camelCase(str) === 'cafeAgard'
pascalCase(str) === 'CafeAgard'
kebabCase(str) === 'cafe-agard'
snakeCase(str) === 'cafe_agard'
constantCase(str) === 'CAFE_AGARD'
// DOES NOT convert special characters:
spaceCase(str) === 'Çâfé Ågård'
pathCase(str) === 'Çâfé/Ågård'
lowerCase(str) === 'çâfé ågård'
upperCase(str) === 'ÇÂFÉ ÅGÅRD'
capitalCase(str) === 'Çâfé Ågård'
With Better Touch Tool you can set up keyboard shortcuts to convert selected text with JavaScript. This repo provides an easy to install preset that has shortcuts for pascal, kebab and camel case! (thanks to @AndrewKoch) It even supports multi-cursors in VSCode!
Here is an example triggering keyboard shortcuts to convert the selected text to PascalCase; kebab-case; camelCase:
You can download the BTT preset from the source code: case-anything.bttpreset.
We'll compare this package with blakeembrey/change-case, a very famous package on npm.
case-anything | change-case | |
---|---|---|
camelCase | 1.1K (572) | 27.2K (6K) |
pascalCase | 1.1K (561) | 27.4K (6.1K) |
kebabCase | 1.1K (541) | 26.8K (5.9K) |
snakeCase | 1.1K (540) | 26.8K (5.9K) |
constantCase | 1.1K (540) | 27.2K (6K) |
pathCase | 1K (530) | 26.8K (5.9K) |
What keeps my package small, is that it's literally just a regex:
export function splitOnSpecialChars (string: string): any[] {
return string.match(/^[a-z]+|[A-Z][a-z]+|[a-z]+|[0-9]+|[A-Z]+(?![a-z])/g)
}
FAQs
camelCase, kebab-case, PascalCase... a simple integration with nano package size. (SMALL footprint!)
The npm package case-anything receives a total of 438,938 weekly downloads. As such, case-anything popularity was classified as popular.
We found that case-anything demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.